<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreatePickupPointVendorsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('ims_yz_pickup_point_vendors', function (Blueprint $table) {
            $table->id();
            
            // 自提点门店ID
            $table->unsignedBigInteger('store_id')->comment('自提点门店ID');
            
            // 供应商ID
            $table->unsignedBigInteger('vendor_id')->comment('供应商ID');
            
            // Laravel 标准时间戳
            $table->timestamps(); // created_at & updated_at
            $table->softDeletes(); // deleted_at
            
            // 联合唯一索引，防止重复关联
            $table->unique(['store_id', 'vendor_id'], 'pickup_point_vendors_unique');
            
            // 普通索引
            $table->index('store_id');
            $table->index('vendor_id');
            $table->index('created_at');
            $table->index('deleted_at');
            
            // 外键约束
            $table->foreign('store_id')->references('id')->on('ims_yz_store')->onDelete('cascade');
            $table->foreign('vendor_id')->references('id')->on('ims_yz_vendor')->onDelete('cascade');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('pickup_point_vendors');
    }
}